package cn.lds.health.dto;

import lombok.Data;

@Data
public class Pager {
	
	private int pageSize = 4;//显示记录数
	private int pageIndex = 1;//当前页
	private int totalRow;//总记录数
	private int totalPage;//总页数
	
	/**
	 * 设置总行数同时，根据上面设置的每页多少行设置总页书
	 *
	 * @param totalRow
	 */
	public void setTotalRow(int totalRow) {
		this.totalRow = totalRow;
		
		this.totalPage = totalRow % pageSize == 0 ? totalRow / pageSize : totalRow / pageSize + 1;
		if (pageIndex > totalPage) {
			pageIndex = totalPage;
		}
		
		if (pageIndex < 1) {
			pageIndex = 1;
		}
		
	}
	
	/**
	 * 设置每一页其实行书
	 *
	 * @return
	 */
	public int getStartIndex() {
		return (pageIndex - 1) * pageSize;
	}
}
